package br.com.caelum.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import br.com.caelum.model.Aluno;
import br.com.caelum.model.Turma;
import br.com.caelum.vraptor.ioc.Component;

@Component
public class TurmaDAO {
	private Session session;
	
	public TurmaDAO(Session session) {
		this.session = session;
	}
	
	public void salva(Turma turma)
	{
		Transaction tx = session.beginTransaction();
		session.save(turma);
		tx.commit();
	}
	
	public void apaga(Turma turma) {
		Transaction tx = session.beginTransaction();
		session.delete(turma);
		tx.commit();
	}
	
	public void atualiza(Turma turma) {
		Transaction tx = session.beginTransaction();
		session.update(turma);
		tx.commit();
	}
	
	public Turma carrega(Long id) {
		return (Turma) this.session.load(Turma.class, id);
	}
	
	public List<Turma> listaTudo() {
		return this.session.createCriteria(Turma.class).list();
	}
	
}

